﻿namespace Away.IdentityServer.Core.Repositories.Base;

public static class SqlBuilder
{
    public static StringBuilder New()
    {
        return new StringBuilder();
    }

    public static StringBuilder New(string str)
    {
        StringBuilder sql = new();
        return sql.Append(str);
    }

    public static StringBuilder Delete(this StringBuilder sql, string tb)
    {
        return sql.Append($" DELETE FROM {tb} ");
    }

    public static StringBuilder Where(this StringBuilder sql, string exp)
    {
        return sql.Append($" WHERE {exp} ");
    }

    public static StringBuilder And(this StringBuilder sql, string str)
    {
        return sql.Append(" and").Append(str);
    }

    public static StringBuilder And(this StringBuilder sql, bool isAdd, string str)
    {
        return isAdd ? sql.Append(" and").Append(str) : sql;
    }

    public static StringBuilder End(this StringBuilder sql)
    {
        return sql.Append(";");
    }

    public static string ToSql(this StringBuilder sql)
    {
        return sql.ToString();
    }
}